package com.zone.vehicle.superApps.view.adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.view.LayoutInflater;

import com.zone.vehicle.lib.view.VerticalTabLayout;
import com.zone.vehicle.superApps.R;
import com.zone.vehicle.superApps.databinding.TabItemLayoutBinding;

public class TabAdapter implements VerticalTabLayout.ViewPagerTabItemCreator {

    private VerticalTabLayout layout;

    private TypedArray tab_icon;
    private TypedArray tab_icon_checked;
    private String[] tab_title;
    private Context context;
    private TabItemLayoutBinding binding;

    public TabAdapter(Context context, VerticalTabLayout layout){
        this.context = context;
        this.layout = layout;
        tab_icon = context.getResources().obtainTypedArray(R.array.tab_icon);
        tab_icon_checked = context.getResources().obtainTypedArray(R.array.tab_icon_checked);
        tab_title = context.getResources().getStringArray(R.array.tab_title);
    }

    @Override
    public VerticalTabLayout.VerticalTab create(int position) {
        VerticalTabLayout.VerticalTab tab = layout.newTab();
        binding = TabItemLayoutBinding.inflate(LayoutInflater.from(context));
        binding.icon.setImageDrawable(tab_icon_checked.getDrawable(position));
        binding.name.setText(tab_title[position]);
        tab.setCustomView(binding.getRoot(), new VerticalTabLayout.OnCustomTabViewRenderListener() {
            @Override
            public void onRender(VerticalTabLayout.VerticalTab tab) {

            }
        });
        return tab;
    }

}
